package com.wechart.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * Created by cxj on 2017/7/10.
 */
public class ImportFactory {

    public static Import getImporter(String exportType, InputStream inputStream) throws Exception {
        if ("xls".equals(exportType)) {
            return new ImportExcel(inputStream);
        }
        else {
            throw new Exception("文件对应处理类不存在");
        }
    }

    public static Import getImporter(File file) throws Exception {
        FileInputStream fis = new FileInputStream(file);
        String fileName = file.getName();
        String exportType = fileName.substring(fileName.lastIndexOf("\\.") + 1, fileName.length());
        return getImporter(exportType, fis);
    }

    public static Import getExporter(String path) throws Exception {
        return getImporter(new File(path));
    }
}
